﻿@extends('layout')
@section('content')

    <style> 
.modal-header-danger {
  color:#fff;
    padding:9px 15px;
    border-bottom:1px solid #eee;
    background-color: #01A9DB;
    -webkit-border-top-left-radius: 5px;
    -webkit-border-top-right-radius: 5px;
    -moz-border-radius-topleft: 5px;
    -moz-border-radius-topright: 5px;
     border-top-left-radius: 5px;
     border-top-right-radius: 5px;
}
    </style>

    </style>
<div class="panel panel-info">
      <div class="panel-heading">
      <h3><left><a href = "#"><img src="./images/insumos.png" height="75px" width="75px"></a></left>Lista de Insumos</h3>
      </div>
    </div>
      <div class="panel panel-info">
    
    <div class="input-group"> <span class="input-group-addon "><span class="glyphicon glyphicon-search"></span> Buscar</span>

    <input name="filter" id="filter" type="text" class="form-control" placeholder="¿Qué desea buscar?"></div>
      <div class="panel-body">
                <table id="insumos" class="table table-striped table-hover display display nowrap" >      
                                <thead>
                                        <tr>
                                                <th>Id</th>
                                                <th>Nombre</th>
                                                <th>Código</th>
                                                <th>Descripción</th>
                                                <th>Tipo Insumo</th>
                                                <th>Acciones</th>
                                        </tr>
                                </thead>
                                <tbody class="searchable">
                                        @foreach($insumos as $insumo)
                                                <tr>
                                                        <td>{{ $insumo->id }}</td>
                                                        <td>{{ $insumo->nombre}}</td>
                                                        <td>{{ $insumo->cod_insumo }}</td>
                                                        <td>{{ $insumo->descripcion }}</td>
                                                        <td>{{TiposInsumos::where('id',$insumo->id_tipo_insumo)->first()->tipo}}</td>
                                                        <td>

  <div class="btn-group">
  <a href="insumos/{{ $insumo->id }}" data-target="#mostrar" data-toggle="modal" class="btn btn-info">Ver</a>
  <a href="#" class="btn btn-info dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
  <ul class="dropdown-menu">
    <li><a href="insumos/{{$insumo->id}}/edit" data-target="#editar" data-toggle="modal">Editar</a></li>
    <li><a href="{{url('/insumos/destroy',$insumo->id)}}">Eliminar</a></li>
  </ul>
</div>
                                                                                                              
                                                        </td>
                                                </tr>
                                        @endforeach
                                </tbody>
                        </table>
                        <button class="btn btn-primary" data-toggle="modal" data-target="#crear"><span class="glyphicon glyphicon-plus"></span> Agregar Insumo</button>
                </div>
        </div>

       @if(Session::has('message'))
            <div class="alert alert-{{ Session::get('class') }}">{{ Session::get('message')}}</div>
        @endif

<!-- Crear -->
<div class="modal fade" id="crear" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header modal-header-danger">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <h1><i class="glyphicon glyphicon-check"></i> Agregar Insumo</h1>
      </div>
        <div class="modal-body">
      {{ Form::open(array('url' => 'insumos')) }}
        <p>{{Form::text('nombre', null, array('class' => 'form-control', 'placeholder' => 'Nombre', 'required' => 'required'))}}</p>
         <p>{{Form::text('cod_insumo', null, array('class' => 'form-control', 'placeholder' => 'Codigo Insumo', 'required' => 'required'))}}</p>
        <p>{{Form::select('id_tipo_insumo',array('0' => 'Seleccione')+TiposInsumos::lists('tipo','id'),null,array('class' => 'form-control','required'))}}</p>
        <p>{{Form::textarea('descripcion', null, array('class' => 'form-control', 'placeholder' => 'Descripción', 'rows' => 3, 'required' => 'required'))}}</textarea></p>
        <p>{{Form::select('id_unidad',array('0' => 'Seleccione')+Unidades::lists('unidad','id'),null,array('class' => 'form-control','required'))}}</p>
      </div> 
      <div class="modal-footer">
        <button type="submit" class="btn btn-warning" style="width: 30%"><span class="glyphicon glyphicon-ok-sign"></span> Guardar</button>
        <button type="button" class="btn btn-default" style="width: 30%" data-dismiss="modal"><span ></span> Regresar</button>
      </div>
    </div> 
  </div>
</div>
<!-- FIN  -->
<!-- Editar -->
<div class="modal fade" id="editar" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <h4 class="modal-title" id="myModalLabel">Editar Insumo</h4>
      </div>
        <div class="modal-body">
             
      </div>
      <div class="modal-footer">
         <button type="submit" class="btn btn-warning" style="width: 30%"><span class="glyphicon glyphicon-ok-sign"></span> Guardar</button>
        <button type="button" class="btn btn-default" style="width: 30%" data-dismiss="modal"><span ></span> Regresar</button>
      </div>
    </div>
  </div>
</div>
<!-- Fin -->
<!-- Mostrar -->
<div class="modal fade" id="mostrar" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <h4 class="modal-title" id="myModalLabel">Ver</h4>
      </div>
        <div class="modal-body">
             
      </div>
      <div class="modal-footer">
        </form>
      </div>
    </div>
  </div>
</div>
<!-- Fin  -->
      
@stop
<script type="text/javascript">
$(document).ready(function() {
$('#insumos').dataTable({
"dom": 'Rlfrtip',
"language": {
"sProcessing":     "Procesando...",
"sLengthMenu":     "Mostrar _MENU_ registros",
"sZeroRecords":    "No se encontraron resultados",
"sEmptyTable":     "Ningún dato disponible en esta tabla",
"sInfo":           "Mostrando registros del _START_ al _END_ de un total de _TOTAL_ registros",
"sInfoEmpty":      "Mostrando registros del 0 al 0 de un total de 0 registros",
"sInfoFiltered":   "(filtrado de un total de _MAX_ registros)",
"sInfoPostFix":    "",
"sSearch":         "Buscar:",
"sUrl":            "",
"sInfoThousands":  ",",
"sLoadingRecords": "Cargando...",
"oPaginate": {
    "sFirst":    "Primero",
    "sLast":     "Último",
    "sNext":     "Siguiente",
    "sPrevious": "Anterior"
            },
        }
} );
var table = $('#insumos').DataTable();

$('#filter').on( 'keyup', function () {
table.search( this.value ).draw();
} );
});
</script>
<script>
   $('#mostrar').on('hidden.bs.modal', function () {
  document.location.reload();
})
   $('#editar').on('hidden.bs.modal', function () {
  document.location.reload();
})  
setTimeout(function() {
    $('#alerta').fadeOut('fast');
}, 2000); // <-- time in milliseconds
</script>




